<?php

class Db_Tables2_BDictParams
{
	function __construct() {
		$this->dealers_db = Zend_Registry::get("dealers_db");
	}
	
	function GetVal($pkey)
	{
		$result = NULL;
		
		$select = $this->dealers_db->select();
		$select->from("b_dict_params", array("pkey", "pval"));
		
		if(is_array($pkey))
		{
			$select->where("pkey IN (?)", $pkey);
			$rows = $this->dealers_db->fetchAll($select);

			if($rows)
			{
				foreach($rows as $row)
				{
					$result[$row['pkey']] = $row['pval'];
				}
			}
		}else{
			$select->where("pkey = ?", $pkey);
			$row = $this->dealers_db->fetchRow($select);

			if($row)
			{
				$result = $row['pval'];
			}
		}
		
		
		return $result;
	}
	
	function GetLevel($role_id)
	{
		$result = 0;
		
		$arr = array(
			"LEVEL-1",
			"LEVEL-2",
			"LEVEL-4",
			"LEVEL-5",
			"LEVEL-6",
			"LEVEL-7",
			"LEVEL-9" //执行主管
		);
		
		$select = $this->dealers_db->select();
		$select->from("b_dict_params", "*");
		$select->where("pkey IN (?)", $arr);
		$rows = $this->dealers_db->fetchAll($select);
		
		if($rows)
		{
			foreach($rows as $row)
			{
				if($role_id == $row['pval'])
				{
					$result = $row['pkey'];
				}
			}
		}
		
		return $result;
	}
    
    function GetSysName()
    {
        $result = "商务系统";
        
        $select = $this->dealers_db->select();
		$select->from("b_dict_params", array("pval"));
		$select->where("pkey = ?", "SYS_NAME");
		$row = $this->dealers_db->fetchRow($select);
		
		if(!empty($row))
		{
			$result = $row['pval'];
		}
        
        return $result;
    }
    
    function GetSysId()
    {
        $id = "";
        
        $select = $this->dealers_db->select();
		$select->from("b_dict_params", array("pval"));
		$select->where("pkey = ?", "SYS_NAME");
		$row = $this->dealers_db->fetchRow($select);
		
		if(!empty($row))
		{
			if('麦尖网络商务系统' == $row['pval'])
            {
                $id = "2";
            }
		}
        
        return $id;
    }
}